package cn.itsource.org.service.impl;

import cn.itsource.basic.service.Impl.BaseServiceImpl;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void add(Employee employee) {
        super.add(employee);
        //保存t_employee_role
        employeeMapper.saveEmpRole(employee.getId(),employee.getRole().getId());
        //保存t_role
//        employeeMapper.saveRole(employee.getRole().getId(),employee.getRole().getName());
    }

    @Override
    public void update(Employee employee) {
        employeeMapper.removeEmpRole(employee.getId());
        super.add(employee);
        employeeMapper.saveEmpRole(employee.getId(),employee.getRole().getId());
    }
}
